package csu.web.mypetstore.controller;

import csu.web.mypetstore.pojo.Orders;
import csu.web.mypetstore.service.AccountService;
import csu.web.mypetstore.service.DeliveryOrderService;
import csu.web.mypetstore.service.OrdersService;
import csu.web.mypetstore.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class OrderController {

    @Autowired
    private DeliveryOrderService deliveryOrderService;
    @Autowired
    private OrdersService ordersService;

    @GetMapping("user/{username}/order")//查看用户包裹
    public Result getOrders(@PathVariable ("username")String username) {

        return ordersService.getPackage(username);
    }
    @DeleteMapping("user/{username}/order/{orderId}")//接收到包裹
    public Result deleteOrder(@PathVariable String username,@PathVariable int orderId) {
        return deliveryOrderService.deleteOrder(username,orderId);
    }
    @PostMapping("user/{username}/order")//添加新的订单
    public Result addNewOrder(@PathVariable String username,@RequestBody Orders orders) {
      return ordersService.addNewOrder(username,orders);

    }
}
